package com.whfc.emp.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whfc.common.exception.BizException;
import com.whfc.common.result.PageData;
import com.whfc.common.result.ResultEnum;
import com.whfc.common.util.PageUtil;
import com.whfc.emp.dao.AppEmpRewardPunishmentMapper;
import com.whfc.emp.dto.AppEmpRewardDTO;
import com.whfc.emp.entity.AppEmpRewardPunishment;
import com.whfc.emp.param.AppEmpRewardAddParam;
import com.whfc.emp.service.AppRewardService;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * @ClasssName AppRewardServiceImpl
 * @Description 人员奖惩
 * @Author hw
 * @Date 2020/12/2 11:45
 * @Version 1.0
 */
@DubboService(interfaceClass = AppRewardService.class, version = "1.0.0")
public class AppRewardServiceImpl implements AppRewardService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AppEmpRewardPunishmentMapper appEmpRewardPunishmentMapper;

    @Override
    public PageData<AppEmpRewardDTO> list(Integer projectId, Integer pageNum, Integer pageSize, Date startDate, Date endDate, String keyword) {
        logger.info("奖惩记录列表,projectId:{},pageNum:{},pageSize:{},startDate:{},endDate:{},keyword:{}",
                projectId, pageNum, pageSize, startDate, endDate, keyword);
        PageHelper.startPage(pageNum, pageSize);
        List<AppEmpRewardDTO> list = appEmpRewardPunishmentMapper.selectByProjectId(projectId, startDate, endDate, keyword);
        return PageUtil.pageData(PageInfo.of(list));
    }

    @Override
    public void add(AppEmpRewardAddParam param) {
        logger.info("添加奖惩记录,param:{}", param);
        AppEmpRewardPunishment record = new AppEmpRewardPunishment();
        BeanUtils.copyProperties(param, record);
        appEmpRewardPunishmentMapper.insertSelective(record);
    }

    @Override
    public void del(Integer id) {
        logger.info("删除奖惩记录,id:{}", id);
        appEmpRewardPunishmentMapper.deleteLogicById(id);
    }

    @Override
    public List<AppEmpRewardDTO> getRewardList(Integer empId) {
        logger.info("根据人员id查找奖惩记录列表,empId:{}", empId);
        List<AppEmpRewardDTO> list = appEmpRewardPunishmentMapper.selectByEmpId(empId);
        return list;
    }

    @Override
    public void delList(List<Integer> ids) {
        logger.info("批量删除奖惩记录,ids:{}", ids);
        if (ids.size()<1) {
            throw new BizException(ResultEnum.PARAM_ERROR.getCode(),"参数验证失败");
        }
        appEmpRewardPunishmentMapper.delList(ids);
    }
}
